load("//tools/lint:lint.bzl", "add_lint_tests")
load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_googletest",
    "drake_cc_library",
    "drake_cc_package_library",
)

package(default_visibility = ["//visibility:public"])

drake_cc_package_library(
    name = "dev",
    visibility = ["//visibility:public"],
    deps = [
        ":mbp_environment_collision_checker",
        ":sphere_robot_model_collision_checker",
        ":voxel_occupancy_map",
        ":voxel_self_filter",
        ":voxel_signed_distance_field",
        ":voxel_tagged_object_occupancy_map",
        ":voxelized_environment_builder",
        ":voxelized_environment_collision_checker",
    ],
)

drake_cc_library(
    name = "sphere_robot_model_collision_checker",
    srcs = ["sphere_robot_model_collision_checker.cc"],
    hdrs = ["sphere_robot_model_collision_checker.h"],
    deps = [
        "//common:essential",
        "//planning:collision_checker",
    ],
    implementation_deps = [
        "@common_robotics_utilities_internal//:common_robotics_utilities",
    ],
)

drake_cc_library(
    name = "mbp_environment_collision_checker",
    srcs = ["mbp_environment_collision_checker.cc"],
    hdrs = ["mbp_environment_collision_checker.h"],
    deps = [
        ":sphere_robot_model_collision_checker",
        "//common:essential",
        "//planning:collision_checker",
    ],
    implementation_deps = [
        "@common_robotics_utilities_internal//:common_robotics_utilities",
    ],
)

drake_cc_library(
    name = "voxel_occupancy_map",
    srcs = [
        "voxel_occupancy_map.cc",
        "voxel_occupancy_map_internal.cc",
        "voxel_occupancy_map_internal.h",
        "voxel_signed_distance_field_internal.cc",
        "voxel_signed_distance_field_internal.h",
    ],
    hdrs = ["voxel_occupancy_map.h"],
    deps = [
        ":voxel_signed_distance_field",
        "//common:essential",
        "//math:geometric_transform",
    ],
    implementation_deps = [
        "@common_robotics_utilities_internal//:common_robotics_utilities",
        "@voxelized_geometry_tools_internal//:voxelized_geometry_tools",
    ],
)

drake_cc_library(
    name = "voxel_grid_internal",
    srcs = [
        "voxel_occupancy_map_internal.cc",
        "voxel_signed_distance_field_internal.cc",
        "voxel_tagged_object_occupancy_map_internal.cc",
    ],
    hdrs = [
        "voxel_grid_internal.h",
        "voxel_occupancy_map_internal.h",
        "voxel_signed_distance_field_internal.h",
        "voxel_tagged_object_occupancy_map_internal.h",
    ],
    tags = ["exclude_from_package"],
    deps = [
        ":voxel_occupancy_map",
        ":voxel_signed_distance_field",
        ":voxel_tagged_object_occupancy_map",
        "//common:essential",
        "@common_robotics_utilities_internal//:common_robotics_utilities",
        "@voxelized_geometry_tools_internal//:voxelized_geometry_tools",
    ],
)

drake_cc_library(
    name = "voxel_signed_distance_field",
    srcs = [
        "voxel_signed_distance_field.cc",
        "voxel_signed_distance_field_internal.cc",
        "voxel_signed_distance_field_internal.h",
    ],
    hdrs = ["voxel_signed_distance_field.h"],
    deps = [
        "//common:essential",
        "//common:parallelism",
    ],
    implementation_deps = [
        "@common_robotics_utilities_internal//:common_robotics_utilities",
        "@voxelized_geometry_tools_internal//:voxelized_geometry_tools",
    ],
)

drake_cc_library(
    name = "voxel_tagged_object_occupancy_map",
    srcs = [
        "voxel_signed_distance_field_internal.cc",
        "voxel_signed_distance_field_internal.h",
        "voxel_tagged_object_occupancy_map.cc",
        "voxel_tagged_object_occupancy_map_internal.cc",
        "voxel_tagged_object_occupancy_map_internal.h",
    ],
    hdrs = ["voxel_tagged_object_occupancy_map.h"],
    deps = [
        ":voxel_signed_distance_field",
        "//common:essential",
        "//math:geometric_transform",
    ],
    implementation_deps = [
        "@common_robotics_utilities_internal//:common_robotics_utilities",
        "@voxelized_geometry_tools_internal//:voxelized_geometry_tools",
    ],
)

drake_cc_library(
    name = "voxelized_environment_collision_checker",
    srcs = ["voxelized_environment_collision_checker.cc"],
    hdrs = ["voxelized_environment_collision_checker.h"],
    deps = [
        ":sphere_robot_model_collision_checker",
        ":voxel_occupancy_map",
        ":voxel_signed_distance_field",
        ":voxel_tagged_object_occupancy_map",
        "//common:essential",
        "//planning:collision_checker",
    ],
    implementation_deps = [
        ":voxel_grid_internal",
        "@common_robotics_utilities_internal//:common_robotics_utilities",
        "@voxelized_geometry_tools_internal//:voxelized_geometry_tools",
    ],
)

drake_cc_library(
    name = "voxelized_environment_builder",
    srcs = [
        "voxelized_environment_builder.cc",
        "voxelized_environment_builder_internal.h",
    ],
    hdrs = ["voxelized_environment_builder.h"],
    deps = [
        ":voxel_occupancy_map",
        ":voxel_tagged_object_occupancy_map",
        "//common:essential",
        "//common:parallelism",
        "//geometry",
        "//multibody/plant",
    ],
    implementation_deps = [
        ":voxel_grid_internal",
        "@common_robotics_utilities_internal//:common_robotics_utilities",
        "@voxelized_geometry_tools_internal//:voxelized_geometry_tools",
    ],
)

drake_cc_library(
    name = "voxel_self_filter",
    srcs = [
        "voxel_self_filter.cc",
        "voxel_self_filter_internal.h",
    ],
    hdrs = ["voxel_self_filter.h"],
    deps = [
        ":sphere_robot_model_collision_checker",
        ":voxel_occupancy_map",
        ":voxel_tagged_object_occupancy_map",
        "//common:essential",
        "//planning:collision_checker",
    ],
    implementation_deps = [
        ":voxel_grid_internal",
        "@common_robotics_utilities_internal//:common_robotics_utilities",
        "@voxelized_geometry_tools_internal//:voxelized_geometry_tools",
    ],
)

drake_cc_library(
    name = "sphere_robot_model_collision_checker_abstract_test_suite",
    testonly = True,
    srcs = [
        "test/sphere_robot_model_collision_checker_abstract_test_suite.cc",
    ],
    hdrs = [
        "test/sphere_robot_model_collision_checker_abstract_test_suite.h",
    ],
    deps = [
        ":sphere_robot_model_collision_checker",
        "//common:nice_type_name",
        "//planning:collision_checker",
        "@googletest//:gtest_for_library",
    ],
    alwayslink = True,
)

drake_cc_googletest(
    name = "mbp_environment_collision_checker_test",
    timeout = "moderate",
    # Be sure to exercise OpenMP-related features.
    num_threads = 2,
    deps = [
        ":mbp_environment_collision_checker",
        ":sphere_robot_model_collision_checker_abstract_test_suite",
        "//planning:planning_test_helpers",
        "//planning/test_utilities:collision_checker_abstract_test_suite",
    ],
)

drake_cc_googletest(
    name = "voxelized_environment_collision_checker_test",
    timeout = "moderate",
    # Be sure to exercise OpenMP-related features.
    num_threads = 2,
    deps = [
        ":sphere_robot_model_collision_checker_abstract_test_suite",
        ":voxel_grid_internal",
        ":voxelized_environment_builder",
        ":voxelized_environment_collision_checker",
        "//planning:planning_test_helpers",
        "//planning/test_utilities:collision_checker_abstract_test_suite",
    ],
)

drake_cc_googletest(
    name = "voxelized_environment_builder_test",
    data = [
        "test/voxel_test1.sdf",
        "test/voxel_test2.sdf",
    ],
    # Be sure to exercise OpenMP-related features.
    num_threads = 2,
    deps = [
        ":voxel_grid_internal",
        ":voxelized_environment_builder",
        "//planning:planning_test_helpers",
        "@common_robotics_utilities_internal//:common_robotics_utilities",
        "@drake//common:essential",
        "@drake//geometry",
        "@drake//multibody/plant",
        "@drake//systems/framework:diagram",
        "@voxelized_geometry_tools_internal//:voxelized_geometry_tools",
    ],
)

drake_cc_googletest(
    name = "voxel_self_filter_test",
    timeout = "moderate",
    data = [
        "@drake_models//:iiwa_description",
    ],
    # Be sure to exercise OpenMP-related features.
    num_threads = 2,
    deps = [
        ":voxel_grid_internal",
        ":voxel_self_filter",
        ":voxelized_environment_collision_checker",
        "//planning:planning_test_helpers",
        "@common_robotics_utilities_internal//:common_robotics_utilities",
        "@drake//common:essential",
        "@drake//geometry",
        "@drake//multibody/plant",
        "@drake//planning:collision_checker",
        "@drake//systems/framework:diagram",
        "@voxelized_geometry_tools_internal//:voxelized_geometry_tools",
    ],
)

add_lint_tests()
